package com.xmu.edu.tisp.task.taskalter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;

import com.xmu.edu.tisp.R;

public class TaskBackDetailAdapter extends ArrayAdapter {
	List<HashMap<String, String>> list;
	HashMap<String, String> checked = new HashMap<String, String>();
	

	public TaskBackDetailAdapter(Context context, List<HashMap<String, String>> list) {
		super(context, R.layout.taskbackdetailitem, list);
		this.list = list;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View item = inflater.inflate(R.layout.taskbackdetailitem, parent,
				false);
		TextView taskname = (TextView) item.findViewById(R.id.tbd_taskname);
		EditText taskvalue = (EditText) item.findViewById(R.id.tbd_value);
		TextView taskunit = (TextView) item.findViewById(R.id.tbd_unit);
		

		HashMap<String, String> map = list.get(position);

		String type=map.get("type");
		if("2".equals(type))
			taskvalue.setGravity(Gravity.CENTER);
		else if("1".equals(type))
		{
			taskvalue.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
		}
		else if("4".equals(type))
		{
			taskvalue.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
		}
		else if("5".equals(type))
		{
			taskvalue.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
		}
		else if("7".equals(type))
		{
			taskvalue.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
		}
		else
		{
			taskvalue.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
		}
		taskname.setText((CharSequence) map.get("name"));
		taskvalue.setText((CharSequence) map.get("value"));
		taskunit.setText((CharSequence) map.get("unit"));
		
		return item;
	}

	

}
